package com.leo.ibatis.demo.service.impl;

import java.util.List;

import com.leo.ibatis.demo.base.Service;
import com.leo.ibatis.demo.criteria.ProductCriteria;
import com.leo.ibatis.demo.dao.ProductDao;
import com.leo.ibatis.demo.domain.Product;
import com.leo.ibatis.demo.service.ProductService;

public class ProductServiceImpl extends Service implements ProductService {

	private ProductDao productDao;

	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}

	public void insert(Product product) {
		productDao.insert(product);
	}

	public int update(Product product) {
		int actualRowsAffected = 0;
		
		String productid = product.getProductid();

		Product _oldProduct = productDao.select(productid);
		
		if (_oldProduct != null) {
			actualRowsAffected = productDao.update(product);
		}
		
		return actualRowsAffected;
	}

	public int delete(String productid) {
		int actualRowsAffected = 0;
		
		Product _oldProduct = productDao.select(productid);
		
		if (_oldProduct != null) {
			actualRowsAffected = productDao.delete(productid);
		}
		
		return actualRowsAffected;
	}
	
	public Product select(String productid) {
		return productDao.select(productid);
	}

	public List<Product> list(ProductCriteria productCriteria) {
		return productDao.list(productCriteria);
	}
	
	public List<Product> listOnPage(ProductCriteria productCriteria) {
		return productDao.listOnPage(productCriteria);
	}

}
